/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2024-02-24 17:22:07
 * @LastEditTime: 2024-02-25 14:01:18
 * @FilePath: /react-vite-admin/src/store/user/index.ts
 */
import { makeAutoObservable } from "mobx";
import { makePersistable } from "mobx-persist-store";

class User {
    userInfo: any = {};//登录用户信息
    token: string = '';//token
    loadingCount: number = 0;//正在请求的数量
    tenantInfo: object = {};//租户信息

    constructor() {
        //自动观察
        makeAutoObservable(this, {}, { autoBind: true });
        //持久化存储
        makePersistable(this, {
            name: 'User',
            properties: ['userInfo', 'token', 'tenantInfo'],
            storage: window.localStorage
        })
    }
    // 设置用户信息
    setUserInfo(info: object) {
        this.userInfo = info;
    }
    // 更新用户token
    setUserToken(token: string) {
        this.token = token;
    }
    //加载请求
    setLoading(count: number) {
        this.loadingCount += count;
    }
    //重置请求数量
    resetLoading(){
        this.loadingCount = 0;
    }
    //设置租户信息
    setTenantInfo(info:object){
        this.tenantInfo = info;
    }
}

export default User;